package com.settlement.system.controller;

import com.settlement.system.model.entity.common.BasePager;
import com.settlement.system.model.entity.common.CommonPlugIn;
import com.settlement.system.model.entity.common.SinglePage;
import com.settlement.system.reply.ObjectDataResponse;
import com.settlement.system.service.RrPlugInService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author
 */
@Slf4j
@RestController
@RequestMapping("/rr/plugin/")
public class RrPlugInController {

    @Resource
    private RrPlugInService rrPlugInService;

    @ApiOperation("记账项目")
    @RequestMapping("recordAccountProject")
    public ObjectDataResponse getRecordAccountProject(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {

            int count = rrPlugInService.getRecordAccountProjectCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getRecordAccountProject(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }


    @ApiOperation("供应商")
    @RequestMapping("getWpRrVendor")
    public ObjectDataResponse getWpRrVendor(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getWpRrVendorCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getWpRrVendor(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("唯品退供差异账单编码")
    @RequestMapping("getWpRdBillCode")
    public ObjectDataResponse getWpRdBillCode(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {

            int count = rrPlugInService.getWpRdBillCodeCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getWpRdBillCode(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("入账主体")
    @RequestMapping("ncEnterAccountBody")
    public ObjectDataResponse getNcEnterAccountBody(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {

            int count = rrPlugInService.getNcEnterAccountBodyCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getNcEnterAccountBody(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("账单类型-全部")
    @RequestMapping("billType")
    public ObjectDataResponse getBillType(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getBillTypeCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getBillType(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("凭证类型")
    @RequestMapping("getVoucherType")
    public ObjectDataResponse getVoucherType(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getVoucherTypeCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getVoucherType(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("店铺")
    @RequestMapping("shop")
    public ObjectDataResponse getShop(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getShopCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getShop(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("线下打款账号")
    @RequestMapping("offlineRemitAccount")
    public ObjectDataResponse getOfflineRemitAccount(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getOfflineRemitAccountCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getOfflineRemitAccount(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("店铺名称（京东）")
    @RequestMapping("shopNameJd")
    public ObjectDataResponse shopNameJd(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getShopNameJdCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getShopNameJd(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("制单人")
    @RequestMapping("editor")
    public ObjectDataResponse getEditor(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getEditorCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getEditor(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }

    @ApiOperation("三级来源")
    @RequestMapping("threeLevelChannel")
    public ObjectDataResponse getThreeChannelNo(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getThreeChannelNoCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getThreeChannelNo(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }


    @ApiOperation("线下打款账号")
    @RequestMapping("oRShopAccount")
    public ObjectDataResponse getOrShopAccount(@RequestBody BasePager<Map<String, Object>> model) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            int count = rrPlugInService.getOrShopAccountCount(model.getModel());
            List<CommonPlugIn> rows = rrPlugInService.getOrShopAccount(new SinglePage(model), model.getModel(),
                    model.getOrderByField(), model.getOrderBy());
            result.put("rows", rows);
            result.put("total", count);
        } catch (Exception ex) {
            log.error("获取列表出错", ex);
            return new ObjectDataResponse(500, "获取列表失败，请联系管理员！");
        }
        return new ObjectDataResponse<Map>(result, 200, "获取列表成功");
    }
}
